 import {geek} from "../../templates/canvas.js";
 import {homeData} from "../../../api/eapi.js";
const pageConfig = {
	data: {
      homeData:'',
		person: [
			{avater: '/images/general_btn_checkbox_sure@2x.png', name: 'Michel Rolland', countryIcon: '/images/general_btn_checkbox_sure@2x.png'},
			{avater: '/images/general_btn_checkbox_sure@2x.png', name: 'Lsabelle Huppert', countryIcon: '/images/general_btn_checkbox_sure@2x.png'}
			],
		multi: true,
    imgURL:null,
    grape:'',
    drink:'',
    readMore:'e'
	},
	changeMulti() {
		this.setData({multi: !this.data.multi})
	},
  onReady:function(){
  let _this=this;
  let nav=geek("geek",this.data.drink);
  nav.draw(false,
    function () {
      wx.canvasToTempFilePath({
        canvasId:"geek",
        success: function (res) {
          var imgUrl = res.tempFilePath;
          _this.setData({
            imgURL: imgUrl
          })
        }
      }, this)
    });
},
onLoad:function(options){
  let _this=this;
    wx.getStorage({
      key: 'productData',
      success: function(res) {

        let grape = res.data.blend_deployment;
        let drink = [];
        _this.setData({homeData:res.data});

        grape.forEach(es =>{
          es['chname']=es.name.split(' ')[0]
        });
        
        if (res.data.deployment=='blend'){
         
          grape.map(res =>{
            drink.push(Number( res.scale ) )
          });
     
          let n = 0;
          if (drink.length > 4){
           
            for (let a = 3; a < drink.length ; a++){
              n += drink[a]
            };

            drink.splice(3,);
            drink.push(n)

          }
        }else{
          drink=[100,0,0,0]
        }
        console.log(res.data)
        homeData(`chateau/${res.data.chateau_id}`,{}).then(es =>{
          _this.setData({
            chateauData:es.data.data
          })
        });

       _this.setData({
         grape:grape,
         drink:drink
       })
      },
    })
},
  readMore(e) {
    let _this = this;
    let n = e.currentTarget.dataset.type;
    let a = _this.data.readMore;

    if (a == n) {
      _this.setData({
        readMore: 'e'
      })
    } else {
      _this.setData({
        readMore: n
      })
    }

  }
}

Page(pageConfig)